using System;
using System.Threading;

namespace Measurements
{   
    public interface IThreadSafeDouble
    {
        double Value { get; set; }   
    }
    
    public struct InterlockedThreadSafeDouble : IThreadSafeDouble
    {
        private long _Value;
        
        public double Value
        {
            get { return BitConverter.Int64BitsToDouble(Interlocked.Read(ref _Value)); }
            set { Interlocked.Exchange(ref _Value, BitConverter.DoubleToInt64Bits(value)); }
        }
    }
    
    public struct LockedThreadSafeDouble : IThreadSafeDouble
    {   
        private readonly object Locker;
        private double _Value;
        
        public double Value
        {
            get { lock (Locker) return _Value; }
            set { lock (Locker) _Value = value; }
        }
        
        public LockedThreadSafeDouble(object init) : this()
        {
            Locker = new object();
        }
    }
}
